package GUI;

import edu.hitsz.application.Main;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author CsCN
 */
public class ChoicePanel {
    private JButton easyButton;
    private JButton normalButton;
    private JButton hardButton;
    private JComboBox musicChoiceBox;
    private JPanel choicePanel;
    private JLabel musicLabel;
    private JPanel easyPanel;
    private JPanel normalPanel;
    private JPanel hardPanel;
    private JPanel musicPanel;

    public ChoicePanel() {
        easyButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setMusicFlag();
                Main.gameMode= Main.GameMode.EASY;
                synchronized (Main.LOCK){
                    Main.LOCK.notify();
                }
            }
        });
        normalButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setMusicFlag();
                Main.gameMode= Main.GameMode.NORMAL;
                synchronized (Main.LOCK){
                    Main.LOCK.notify();
                }
            }
        });
        hardButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setMusicFlag();
                Main.gameMode= Main.GameMode.HARD;
                synchronized (Main.LOCK){
                    Main.LOCK.notify();
                }
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("ChoicePanel");
        frame.setContentPane(new ChoicePanel().choicePanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    public JPanel getPanel(){
        return choicePanel;
    }

    private void setMusicFlag(){
        Main.musicFlag = musicChoiceBox.getSelectedIndex() == 0;
    }
}
